package com.ychug.framework.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.sql.DataSource;

    @Configuration
    public class DataSourceAutoConfiguration {
        //从配置中心获取参数
//        @Value("${mysql.username}:root")
//        private String userName;
//        @Value("${mysql.url}")
//        private String url;
//        @Value("${mysql.driver-class-name}")
//        private String driverClassName;
//        @Value("${mysql.safe}")
//        private  String safe ;
//        @Value("${mysql.object}")
//        private  String object ;
//        @Value("${mysql.appId}")
//        private String  appId;
//        @Value("${mysql.reason}")
//        private String reason;
//        @Value("${mysql.folder}")
//        private String folder;
//        @Value("${mysql.key}")
//        private String key;
//        @Value("${mysql.remoteurl}")
//        private String remoteUrl;
//
//        @Value("${mysql.max-active:200}")
//        private int maxActive;
//        @Value("${mysql.initial-size:20}")
//        private int initialSize;
//        @Value("${mysql.max-wait:5000}")
//        private int maxWait;
//        @Value("${mysql.min-idle:20}")
//        private int minIdle;


        @Resource
        DataSourceProperties properties;

        @Bean
        public DataSource dataSource() {
            DruidDataSource druidDataSource=new DruidDataSource();
            druidDataSource.setUrl("jdbc:mysql://localhost:3306/mcpcms?serverTimezone=UTC");
            druidDataSource.setUsername("root");
            druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");

            String password = "123456";// provider.getPassword(safe, folder, object, null);
            druidDataSource.setPassword(password);
//            druidDataSource.setMaxActive(maxActive);
//            druidDataSource.setInitialSize(initialSize);
//            druidDataSource.setMinIdle(minIdle);
//            druidDataSource.setMaxWait(maxWait);
//            druidDataSource.setTestOnBorrow(true);
//            druidDataSource.setTestOnReturn(true);

            return druidDataSource;
            //return DataSourceBuilder.create().url(properties.getUrl()).username(properties.getUsername()).password(properties.getPassword()).driverClassName(properties.getDriverClassName()).build();//.type(ComboPooledDataSource.class).build();
        }

    }
